<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>登录界面</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <script th:src="@{/loginStatic/static/js/jquery-1.11.3.min.js}"></script>
    <link rel="stylesheet" th:href="@{/loginStatic/static/css/pintuer.css}">
    <link rel="stylesheet" th:href="@{/loginStatic/static/css/admin.css}">
    <script th:src="@{/loginStatic/static/js/pintuer.js}"></script>
    <script th:src="@{/loginStatic/static/js/bootstrap.min.js}"></script>
</head>
<body>
<div class="bg"></div>
<div class="container">
    <div class="line bouncein">
        <div class="xs6 xm4 xs3-move xm4-move">
            <div style="height:20px;"></div>
            <div class="media media-y margin-big-bottom">
            </div>
            <form th:action="@{/login}" method="post">
                <div class="panel loginbox">
                    <div class="text-center margin-big padding-big-top"><h1>MyHome销售管理台</h1></div>
                    <div class="panel-body" style="padding:30px; padding-bottom:10px; padding-top:10px;">
                        <p id="errorMessage"></p>
                        <div class="form-group">
                            <div class="field field-icon-right">
                                <input id="userName" type="text" class="input input-big" name="userName"
                                       placeholder="登录账号" data-validate="required:请填写账号"/>
                                <span class="icon icon-user margin-small"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="field field-icon-right">
                                <input id="pwd" type="password" class="input input-big" name="password"
                                       placeholder="登录密码" data-validate="required:请填写密码"/>
                                <span class="icon icon-key margin-small"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="field field-icon-right">
                                <select id="select_role">
                                    <option value="1">经理</option>
                                    <option value="2">销售人员</option>

                                </select>
                            </div>
                        </div>

                    </div>
                    <div style="padding:30px;">
                        <input type="button" class="button button-block bg-main text-big input-big" value="登录" onclick="login()">
                    </div>
                </div>
            </form>
            <!-- 出错显示的信息框 -->
            <div class="alert alert-warning alert-dismissible" role="alert" hidden>
                <button type="button" class="close" data-dismiss="alert">
                    <span>&times;</span>
                </button>
                <strong>${login_msg}</strong>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" th:inline="javascript">
    function login() {
        var userName = $("[name='userName']").val();//获取输入的账号
        var userPwd = $("[name='password']").val();//获取输入的密码
         console.log(userName);
        //$("#sel option:selected").val()
        var userRole = $("#select_role option:selected").val();
        /*console.log(userRole);*/

        alert(userName);
        $.ajax({
            url: [[@{/login}]],
            type: "POST",
                /*这边的userRole我先写死你们到时候在改*/
            data: {"userName": userName, "password": userPwd },
            success: function (data) {
                console.log(data);336
                if (data.status == 200) {
                   alert("成功");

                    location.href = [[@{/mianban}]];
                }else {
                    console.log("后台没有传数据过来");
                    $("#errorMessage").text(data.message);
                }
            },
            error: function (data) {
                $("#errorMessage").text(data.responseText);
            }
        });
    }
</script>
</html>